home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / MSG Demo 1.4.source Folder / Demo ƒ / Fades ƒ / Scissors fade.c < prev    next >
Text File  |  1994-04-15  |  3KB  |  105 lines

  1. /**********************************************************************\
  2.  
  3. File:        Scissors fade.c
  4.  
  5. Purpose:    Graphic effect to fade main window to solid pattern.
  6.             See comments below for more description.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program in a file named "GNU General Public License".
  20. If not, write to the Free Software Foundation, 675 Mass Ave,
  21. Cambridge, MA 02139, USA.
  22.  
  23. \**********************************************************************/
  24.  
  25. #include "timing.h"
  26.  
  27. #define CorrectTime 3
  28. #define theWindowWidth (boundsRect.right-boundsRect.left)
  29. #define theWindowHeight (boundsRect.bottom-boundsRect.top)
  30.  
  31. pascal short ScissorsFade(Rect boundsRect, Pattern *thePattern);
  32.  
  33. /* A region in two parts, starting at the top of the left and right sides and
  34.    moving down the sides and together towards the middle of the bottom side. */
  35.    
  36. pascal short ScissorsFade(Rect boundsRect, Pattern *thePattern)
  37. {
  38.     RgnHandle        curregion, boundsRgn, sectrgn;
  39.     int                cx,gap,lastx,lasty;
  40.     int                BlockSize;
  41.     
  42.     BlockSize=theWindowHeight/25;
  43.     cx = theWindowWidth / 2;
  44.  
  45.     boundsRgn=NewRgn();
  46.     RectRgn(boundsRgn, &boundsRect);
  47.     sectrgn=NewRgn();
  48.     curregion=NewRgn();
  49.     gap=BlockSize;
  50.     lasty=0;
  51.     do
  52.     {
  53.         StartTiming();
  54.         SetEmptyRgn(curregion);
  55.         MoveTo(cx,0);
  56.         OpenRgn();
  57.             LineTo(theWindowWidth,lasty);   /* get the right half */
  58.             LineTo(theWindowWidth,gap);
  59.             LineTo(cx,0);
  60.             LineTo(0,lasty);                   /* get the left half */
  61.             LineTo(0,gap);
  62.             LineTo(cx,0);
  63.         CloseRgn(curregion);
  64.         OffsetRgn(curregion, boundsRect.left, boundsRect.top);
  65.         SectRgn(curregion, boundsRgn, sectrgn);
  66.         FillRgn(sectrgn, *thePattern);
  67.         lasty=gap;
  68.         gap+=BlockSize;
  69.         TimeCorrection(CorrectTime);
  70.     }
  71.     while (gap<theWindowHeight+BlockSize);
  72.     
  73.     lastx=theWindowWidth;
  74.     gap=theWindowWidth-BlockSize;
  75.     do
  76.     {
  77.         StartTiming();
  78.         SetEmptyRgn(curregion);
  79.         MoveTo(cx,0);
  80.         OpenRgn();
  81.             LineTo(lastx,theWindowHeight);        /* get the right half on bottom side */
  82.             LineTo(gap,theWindowHeight);
  83.             LineTo(cx,0);
  84.             LineTo(theWindowWidth-lastx,theWindowHeight);    /* left 1/2 on bottom */
  85.             LineTo(theWindowWidth-gap,theWindowHeight);
  86.             LineTo(cx,0);
  87.         CloseRgn(curregion);
  88.         OffsetRgn(curregion, boundsRect.left, boundsRect.top);
  89.         SectRgn(curregion, boundsRgn, sectrgn);
  90.         FillRgn(sectrgn, *thePattern);
  91.         lastx=gap;
  92.         gap-=BlockSize;
  93.         TimeCorrection(CorrectTime);
  94.     }
  95.     while (gap>theWindowWidth/2);
  96.     
  97.     FillRect(&boundsRect, *thePattern);            /* if we missed any bits */
  98.     
  99.     DisposeRgn(curregion);
  100.     DisposeRgn(boundsRgn);
  101.     DisposeRgn(sectrgn);
  102.     
  103.     return 0;
  104. }
  105.